public class work2 {
    public int[] searchRange(int[] nums, int target) {
        int []arr=new int[2];
        boolean flg=true;
        int left=0,right=nums.length-1;
        //求左端点
        while(left<right){
            int mid=left+(right-left)/2;
            if(nums[mid]>=target){
                right=mid;
            }
            if(nums[mid]<target)left=mid+1;
            if(nums[mid]==target)flg=false;
        }
        arr[0]=left;
        //求右端点
        left=0;
        right=nums.length-1;
        while(left<right){
            int mid=left+(right-left+1)/2;
            if(nums[mid]>target){
                right=mid-1;
            }
            if(nums[mid]<=target){
                left=mid;
            }
            if(nums[mid]==target)flg=false;
        }
        arr[1]=left;
        if(flg)arr[0]=arr[1]=-1;
        if(nums.length==1&&nums[0]==target)arr[0]=arr[1]=0;
        return arr;
    }
}
